import {
	zone
} from '@/api/Zone.js'
import {
	Top,
	home_new,
	home_tui,
	home_url,
	details_xq,
	getcart,
	addcart,
	search,
	navfl,
	login,
	delcart,
	clearAll,
	GetAddress
} from '@/api/Top.js'
const state = {
	vuexStr: '',
	vuexTop: '',
	vuexNew: '',
	vuexTui: '',
	vuexUrl: '',
	vuexXq: '',
	vuexGetCart: '',
	vuexAddCart: '',
	vuexSearch: '',
	vuexNavfl: '',
	vuexLogin: '',
	vuexDelCart: '',
	vuexClearAll: '',
	vuexGetAddress: ''
}
const mutations = {

	SET_VUEXZONE: (state, data) => {
		state.vuexStr = data
	},
	// 轮播图
	SET_VUEXTOP: (state, data) => {
		state.vuexTop = data
	},
	// 最新
	SET_VUEXNEW: (state, data) => {
		state.vuexNew = data
	},
	// 推荐
	SET_VUEXTUI: (state, data) => {
		state.vuexTui = data
	},
	// 路由拼接
	SET_VUEXURL: (state, data) => {
		state.vuexUrl = data
	},
	// 详情
	SET_VUEXXq: (state, data) => {
		state.vuexXq = data
	},
	// 获取购物车
	SET_VUEXGETCART: (state, data) => {
		state.vuexGetCart = data
	},
	// 添加购物车
	SET_VUEXADDCART: (state, data) => {
		state.vuexAddCart = data
	},
	// 搜索
	SET_VUEXSEARCH: (state, data) => {
		state.vuexSearch = data
	},
	// nav详情
	SET_VUEXNAVFL: (state, data) => {
		state.vuexNavfl = data
	},
	// 登录
	SET_VUEXLOGIN: (state, data) => {
		state.vuexLogin = data
	},
	// 删除
	SET_VUEXDELCART: (state, data) => {
		state.vuexDelCart = data
	},
	// 清空购物车
	SET_VUEXCLEARALL: (state, data) => {
		state.vuexClearAll = data
	},
	// 获取地理位置
	SET_VUEXGETADDRESS: (state, data) => {
		state.vuexGetAddress = data
	}
}
const actions = {
	vuexZone({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var zoneState = zone()
			if (zoneState) {
				commit('SET_VUEXZONE', zoneState + data)
				res(zoneState)
			} else {
				rej('失败')
			}
		})
	},
	// 轮播图
	vuexTop({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var topState = Top()
			if (topState) {
				commit('SET_VUEXTOP', topState + data)
				res(topState)
			} else {
				rej('失败')
			}
		})
	},
	// 最新
	vuexNew({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var newState = home_new()
			if (newState) {
				commit('SET_VUEXNEW', newState + data)
				res(newState)
			} else {
				rej('失败')
			}
		})
	},
	// 推荐
	vuexTui({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var tuiState = home_tui()
			if (tuiState) {
				commit('SET_VUEXTUI', tuiState + data)
				res(tuiState)
			} else {
				rej('失败')
			}
		})
	},
	// 路由拼接
	vuexUrl({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var urlState = home_url()
			if (urlState) {
				commit('SET_VUEXURL', urlState + data)
				res(urlState)
			} else {
				rej('失败')
			}
		})
	},
	// 获取详情
	vuexXq({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var xqState = details_xq(data)
			if (xqState) {
				commit('SET_VUEXXq', xqState + data)
				res(xqState)
			} else {
				rej('失败')
			}
		})
	},
	// 获取购物车
	vuexGetCart({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var getcartState = getcart(data)
			if (getcartState) {
				commit('SET_VUEXGETCART', getcartState + data)
				res(getcartState)
			} else {
				rej('失败')
			}
		})
	},
	// 添加购物车
	vuexAddCart({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var addcartState = addcart(data)
			if (addcartState) {
				commit('SET_VUEXGETCART', addcartState + data)
				res(addcartState)
			} else {
				rej('失败')
			}
		})
	},
	// 搜索
	vuexSearch({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var searchState = search(data)
			if (searchState) {
				commit('SET_VUEXSEARCH', searchState + data)
				res(searchState)
			} else {
				rej('失败')
			}
		})
	},
	// nav分类
	vuexNavfl({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var navflState = navfl(data)
			if (navflState) {
				commit('SET_VUEXNAVFL', navflState + data)
				res(navflState)
			} else {
				rej('失败')
			}
		})
	},
	// 登录
	vuexLogin({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var loginState = login(data)
			if (loginState) {
				commit('SET_VUEXLOGIN', loginState + data)
				res(loginState)
			} else {
				rej('失败')
			}
		})
	},
	// 删除购物车
	vuexDelCart({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var delcartState = delcart(data)
			if (delcartState) {
				commit('SET_VUEXDELCART', delcartState + data)
				res(delcartState)
			} else {
				rej('失败')
			}
		})
	},
	// 清空购物车
	vuexClearAll({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var clearAllState = clearAll(data)
			if (clearAllState) {
				commit('SET_VUEXCLEARALL', clearAllState + data)
				res(clearAllState)
			} else {
				rej('失败')
			}
		})
	},
	// 获取地理位置
	vuexGetAddress({
		commit
	}, data) {
		// return zone()
		return new Promise((res, rej) => {
			var GetAddressState = GetAddress(data)
			if (GetAddressState) {
				commit('SET_VUEXGETADDRESS', GetAddressState + data)
				res(GetAddressState)
			} else {
				rej('失败')
			}
		})
	},
}
export default {
	namespaced: true,
	actions,
	mutations,
	state
}
